home *** CD-ROM | disk | FTP | other *** search
/ NASA Climatology Interdisciplinary Data Collection / NASA Climatology Interdisciplinary Data Collection - Disc 4.iso / software / grads / lib / cbar.gs < prev    next >
Encoding:
Text File  |  1998-04-23  |  2.0 KB  |  95 lines

  1. *
  2. *  Script to plot a colorbar
  3. *
  4. *  The script will assume a colorbar is wanted even if there is 
  5. *  not room -- it will plot on the side or the bottom if there is
  6. *  room in either place, otherwise it will plot along the bottom and
  7. *  overlay labels there if any.  This can be dealt with via 
  8. *  the 'set parea' command.  In version 2 the default parea will
  9. *  be changed, but we want to guarantee upward compatibility in
  10. *  sub-releases.
  11. *
  12. function colorbar (args)
  13. *
  14. *  Check shading information
  15. *
  16.   'query shades'
  17.   shdinfo = result
  18.   if (subwrd(shdinfo,1)='None') 
  19.     say 'Cannot plot color bar: No shading information'
  20.     return
  21.   endif
  22. *  Get plot size info
  23. *
  24.   'query gxinfo'
  25.   rec2 = sublin(result,2)
  26.   rec3 = sublin(result,3)
  27.   rec4 = sublin(result,4)
  28.   xsiz = subwrd(rec2,4)
  29.   ysiz = subwrd(rec2,6)
  30.   ylo = subwrd(rec4,4)
  31.   xhi = subwrd(rec3,6)
  32.   xd = xsiz - xhi
  33. *
  34. *  Decide if horizontal or vertical color bar
  35. *  and set up constants.
  36. *
  37.   if (ylo<0.6 & xd<1.0) 
  38.     say "Not enough room in plot for a colorbar"
  39.     return
  40.   endif
  41.   cnum = subwrd(shdinfo,5)
  42.   if (ylo<0.6 | xd>1.5)
  43.     xl = xhi + xd/2 - 0.4
  44.     xr = xl + 0.2
  45.     xwid = 0.2
  46.     ywid = 0.5
  47.     if (ywid*cnum > ysiz*0.8) 
  48.       ywid = ysiz*0.8/cnum
  49.     endif
  50.     ymid = ysiz/2
  51.     yb = ymid - ywid*cnum/2
  52.     'set string 1 l 5'
  53.     vert = 1
  54.   else
  55.     ymid = ylo/2
  56.     yt = ymid + 0.2
  57.     yb = ymid
  58.     xmid = xsiz/2
  59.     xwid = 0.8
  60.     if (xwid*cnum > xsiz*0.8)
  61.       xwid = xsiz*0.8/cnum
  62.     endif
  63.     xl = xmid - xwid*cnum/2
  64.     'set string 1 tc 5'
  65.     vert = 0
  66.   endif
  67. *
  68. *  Plot colorbar
  69. *
  70.   'set strsiz 0.12 0.13'
  71.   num = 0
  72.   while (num<cnum) 
  73.     rec = sublin(shdinfo,num+2)
  74.     col = subwrd(rec,1)
  75.     hi = subwrd(rec,3)
  76.     'set line 'col
  77.     if (vert) 
  78.       yt = yb + ywid
  79.     else 
  80.       xr = xl + xwid
  81.     endif
  82.     'draw recf 'xl' 'yb' 'xr' 'yt
  83.     if (num<cnum-1)
  84.       if (vert) 
  85.         'draw string '%(xr+0.05)%' 'yt' 'hi
  86.       else
  87.         'draw string 'xr' '%(yb-0.05)%' 'hi
  88.       endif
  89.     endif
  90.     num = num + 1
  91.     if (vert); yb = yt;
  92.     else; xl = xr; endif;
  93.   endwhile
  94.